package com.wxb.cardmis.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * All rights Reserved, Designed By www.super-master.cn
 *
 * @ProjectName: cardmis
 * @Package: com.wxb.cardmis.config
 * @ClassName: HeaderFilter
 * <p> </p>
 * @Author: [Wei Xiao]
 * @Date: 2022/2/21 23:16
 * @Version: V1.0
 * @Copyright: 2022  com.wei All rights reserved.
 * TODO: 注意,本文件Wei Xiao所作,如果转载或使用请标明具体出处!
 * @Date: 2022年02月21日 23:16
 * @Description: []
 **/
//@WebFilter(urlPatterns = "/*",filterName = "headerFilter")
public class HeaderFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        /**
         * 解决跨域访问
         */
        response.setContentType("text/html;charset = UTF-8");
        response.setHeader("Access-Control-Allow-Origin",request.getHeader("Origin"));
        response.setHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,DELETE");
        response.setHeader("Access-Control-Max-Age","0");
        response.setHeader("Access-Control-Allow-Headers ","Origin,No-Cache,X-Request-With,If-Modified-Since,Pragma,Last-Modified,Cache-Control,Expires,Content-Type,X-E4M-With,token");
        response.setHeader("Access-Control-Allow-Credentials","true");

        filterChain.doFilter(request,response);



    }
}
